#include "Stdafx.h"
#include "WinApi.h"

using namespace Vortex::Wrapper::Platform;

System::Drawing::Rectangle WinApi::GetWindowClientRect(IntPtr windowHandle) {
	RECT rect;
	GetClientRect((HWND)windowHandle.ToPointer(), &rect);
	return System::Drawing::Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}

///<summary>Converts client point into screen coordinate space</summary>
System::Drawing::Point WinApi::ClientToScreen(IntPtr windowHandle, System::Drawing::Point localPoint) {
	POINT p = { localPoint.X, localPoint.Y };
	::ClientToScreen((HWND)windowHandle.ToPointer(), &p);
	return System::Drawing::Point(p.x, p.y);
}


HitTestResult WinApi::TestWindowPoint(IntPtr windowHandle) {
	HWND hWindow = (HWND)windowHandle.ToPointer();
	POINT point;
	GetCursorPos(&point);

	bool thisWindow = (hWindow == WindowFromPoint(point));
	
	if (thisWindow) {
		return (HitTestResult)DefWindowProc(hWindow, WM_NCHITTEST, 0, (point.x & 0xFFFF) | (point.y & 0xFFFF) << 16);
	} else {
		return HitTestResult::Nowhere;
	}
}